import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:kepu/page/plant_list_page/provider/plant_list_provider.dart';

import '../../widgets/custom_grid_view.dart';
import '../../widgets/error_widget.dart';
import '../../widgets/loading_widget.dart';

class PlantListPage extends ConsumerWidget {
  const PlantListPage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    var plantList = ref.watch(plantListProvider);
    return Scaffold(
      body: plantList.when(
        data:
            (list) => EasyRefresh(
          onRefresh:()=> ref.refresh(plantListProvider.future),
          onLoad: (){
            ref.read(plantListProvider.notifier).add();
          },
          child: Padding(
            padding: const EdgeInsets.fromLTRB(10, 0, 10, 10),
            child: CustomScrollView(
              slivers: [customGridView(itemList: list, isPlant: true)],
            ),
          ),
        ),
        error: (e, st) => errorWidget(),
        loading: () => loadWidget(context),
      ),
    );
  }
}
